/**
 * 
 */
package cn.edu.fjnu.camera;

import cn.edu.fjnu.camera.R;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;


public class CameraSettings extends PreferenceActivity implements OnSharedPreferenceChangeListener{
	private ListPreference mWhiteBalanceListPreference;
	private ListPreference mAntiBandingListPreference;
	private SharedPreferences mPrefs;
	private SharedPreferences.Editor mPrefsEditor;
	protected void onCreate(Bundle savedInstanceState) { 
	
	    super.onCreate(savedInstanceState); 
	    addPreferencesFromResource(R.xml.camera_preferences); 
	      
	    mPrefs = getPreferenceManager().getDefaultSharedPreferences(this);
	    mWhiteBalanceListPreference = (ListPreference)getPreferenceScreen().findPreference("WhiteBalance");
	    mAntiBandingListPreference = (ListPreference)getPreferenceScreen().findPreference("AntiBanding");
	      
	}
	  
	protected void onResume()
	{
		super.onResume();
		//根据EntryValue的值设定Summary
		mWhiteBalanceListPreference.setSummary(mWhiteBalanceListPreference.getEntry());
		mAntiBandingListPreference.setSummary(mAntiBandingListPreference.getEntry());
        mPrefsEditor = mPrefs.edit();
        
		getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
		  
	}
	
	protected void onPause()
	{
		super.onPause();
		getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
		mPrefsEditor.commit();
	}
	  
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
	{//响应Preference改变事件，更改summary
		if(key.equals("WhiteBalance")){
			mWhiteBalanceListPreference.setSummary(mWhiteBalanceListPreference.getEntry());
		}
		else if(key.equals("AntiBanding"))
		{
			mAntiBandingListPreference.setSummary(mAntiBandingListPreference.getEntry());
		}
	}
}
